<?php

class Order extends Controller {
	
	function Order()
	{
		parent::Controller();
	}
	
	function index() {
		$id = $this->uri->segment(3);
		//load Model
		$this->load->model('Product_model');
		$this->load->model('Member_model');

		$ary_where = array('p.id'=>$id);
		$form_info = $this->Product_model->getProduct($ary_where);

		$data['form_info'] = $form_info;		
		$data['inc_script'] = '<script type="text/javascript" src="'.base_url().'js/order.js"></script>';
		$this->load->view('order_view',$data);
	}
	
	function add() {
		//check login
		if (!$this->session->userdata('ss_email') || $this->session->userdata('ss_member_type')!=2) {
			redirect('login');
		}
		
		//load Model
		$this->load->model('Order_model');
		
		if ($this->input->post('btn_order')) {
			//get value from form
			$order_info = array(
				'product_id' => $this->input->post('h_product_id'),
				'member_id' => $this->session->userdata('ss_member_id'),
				'quantity' => $this->input->post('tf_quantity'),
				'date_pay' => date('Y-m-d h:i:s'),
				'date_delivery' => date('Y-m-d h:i:s'),
				'money_pay' => $this->input->post('h_money_pay'),
			);
			
			$this->Order_model->addOrder($order_info);
			redirect('order/success');
		}
	}
	
	function success() {
		$data['inc_script'] = '';
		$this->load->view('order_success_view',$data);	
	}
}